<?php
require_once "../lib/common.php";
require_once "../congfig/config.php";

$results = $_POST['p1'];
if (empty($_POST['p1'])) {
    echo(1);
}
$zipname = date('Y-m-d', time()) . '_' . uniqid() . ".zip";
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);

foreach ($results as $result) {
    $sql = "SELECT *  FROM `proinfor` WHERE id = '$result'";
    $query = $GLOBALS['conn']->query($sql);
    $row = $query->fetch_array();
    $path = filepath . $row['Enclosure'];
    // exit(jsoncall(-1,"$path"));  
    if (file_exists($path)) {
        $zip->addFile($path);
    }
}
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=' . $zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
